package com.dsjy.yf.address.config.globalprocess;




import com.dsjy.yf.address.config.base.BaseErrorInfoInterface;
import com.dsjy.yf.address.config.base.BizException;
import com.dsjy.yf.address.config.base.CommonEnum;
import lombok.Data;

@Data
public class Result<T> {
    // 失败的具体code
    // 接口调用成功或者失败
    private Integer errorCode = CommonEnum.SUCCESS.getResultCode();
    // 需要传递的信息，例如错误信息
    private String message = CommonEnum.SUCCESS.getResultMsg();
    private boolean success = true;
    // 需要传递的数据
    private T data;

    public Result(T data) {
        this.data = data;
    }

    public Result() {
    }

    /**
     * 失败
     */
    public static Result error(BaseErrorInfoInterface errorInfo) {
        Result rb = new Result();
        rb.setErrorCode(errorInfo.getResultCode());
        rb.setMessage(errorInfo.getResultMsg());
        rb.setData(null);
        rb.setSuccess(false);
        return rb;
    }

    /**
     * 失败
     */
    public static Result error(BizException errorInfo) {
        Result rb = new Result();
        rb.setErrorCode(errorInfo.getErrorCode());
        rb.setMessage(errorInfo.getErrorMsg());
        rb.setData(null);
        rb.setSuccess(false);
        return rb;
    }

}
